package com.lijie.ljblog.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lijie.ljblog.model.Blog;
import com.lijie.ljblog.model.Link;
import com.lijie.ljblog.model.Liuyan;
import com.lijie.ljblog.model.Person;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class QueryWrapperUtil {
    public QueryWrapper<Blog> getBlogQueryWrapper(Blog blog){
        QueryWrapper<Blog> queryWrapper = new QueryWrapper<>();
        if(blog!=null){
            if(blog.getId()!=null){
                queryWrapper.eq("Id",blog.getId());
            }
            if(blog.getBlogType()!=null){
                queryWrapper.eq("blogType",blog.getBlogType());
            }
            if(blog.getBlogClassify()!=null){
                queryWrapper.eq("blogClassify",blog.getBlogClassify());
            }
            if(blog.getTitle()!=null){
                queryWrapper.eq("blogTitle",blog.getTitle());
            }
            if(blog.getBlogStatus()!=null){
                queryWrapper.eq("blogStatus",blog.getBlogStatus());
            }
        }
        queryWrapper.orderByDesc("id");
        return queryWrapper;
    }
    public QueryWrapper<Person> getPersonQueryWrapper(Person person){
        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        if(person!=null){
            if(person.getId()!=null){
                queryWrapper.eq("Id",person.getId());
            }
            if(person.getUserName()!=null){
                queryWrapper.eq("username",person.getUserName());
            }
            if(person.getType()!=null){
                queryWrapper.eq("type",person.getType());
            }if(person.getEmail()!=null){
                queryWrapper.eq("email",person.getEmail());
            }
        }
        return queryWrapper;
    }
    public QueryWrapper<Liuyan> getLiuyanQueryWrapper(Liuyan liuyan){
        QueryWrapper<Liuyan> queryWrapper = new QueryWrapper<>();
        if(liuyan!=null){
            if(liuyan.getId()!=null){
                queryWrapper.eq("Id",liuyan.getId());
            }
            if(liuyan.getBlogid()!=null){
                queryWrapper.eq("blogId",liuyan.getBlogid());
            }
            if(liuyan.getPersonId()!=null){
                queryWrapper.eq("personId",liuyan.getPersonId());
            }
        }
        return queryWrapper;
    }
    public QueryWrapper<Link> getLinkQueryWrapper(Link link){
        QueryWrapper<Link> queryWrapper = new QueryWrapper<>();
        if(link!=null){
            if(link.getId()!=null){
                queryWrapper.eq("id",link.getId());
            }
            if(StringUtils.isNotEmpty(link.getLinkName())){
                queryWrapper.eq("linkName",link.getLinkName());
            }
            if(StringUtils.isNotEmpty(link.getStatus())){
                queryWrapper.eq("status",link.getStatus());
            }
        }
        return queryWrapper;
    }
}
